package lk.icta.common.entity;

import lk.icta.core.entity.ModuleType;

import javax.persistence.*;
import java.io.File;
import java.io.Serializable;

/**
 * @author Mahesha Kalpanie
 */
@Entity
@Table(schema = "COMMON_RAIL")
@NamedQueries({
        @NamedQuery(
                name = "getDocumentsByModuleAndModuleId",
                query = "SELECT d FROM Document d WHERE d.moduleId = :moduleId and d.moduleType = :moduleType"
        )
})
public class Document extends BaseEntity {

    @Column(nullable = false)
    private String location;

    @Column
    private String uploadUrl;

    @Column
    private String documentUuid;

    @Transient
    private byte[] fileContent;

    @Column(nullable = false)
    private String contentType;

    @Column(nullable = false)
    private ModuleType moduleType;

    @Column(nullable = false)
    private long moduleId;

    @Column(nullable = false)
    private String documentName;

    @Column
    private String extension;

    @Transient
    private File file;

    @Transient
    private String fileName;

    @ManyToOne(cascade = {CascadeType.REFRESH})
    @JoinColumn(nullable = true)
    private DocumentCategory documentCategory;

    public String getLocation() {
        return location;
    }

    public void setLocation(String location) {
        this.location = location;
    }

    public String getContentType() {
        return contentType;
    }

    public void setContentType(String contentType) {
        this.contentType = contentType;
    }

    public ModuleType getModuleType() {
        return moduleType;
    }

    public void setModuleType(ModuleType moduleType) {
        this.moduleType = moduleType;
    }

    public long getModuleId() {
        return moduleId;
    }

    public void setModuleId(long moduleId) {
        this.moduleId = moduleId;
    }

    public String getDocumentName() {
        return documentName;
    }

    public void setDocumentName(String documentName) {
        this.documentName = documentName;
    }

    public String getExtension() {
        return extension;
    }

    public void setExtension(String extension) {
        this.extension = extension;
    }

    public File getFile() {
        return file;
    }

    public void setFile(File file) {
        this.file = file;
    }

    public String getFileName() {
        return fileName;
    }

    public void setFileName(String fileName) {
        this.fileName = fileName;
    }

    public DocumentCategory getDocumentCategory() {
        return documentCategory;
    }

    public void setDocumentCategory(DocumentCategory documentCategory) {
        this.documentCategory = documentCategory;
    }

    public byte[] getFileContent() {
        return fileContent;
    }

    public void setFileContent(byte[] fileContent) {
        this.fileContent = fileContent;
    }

    public String getUploadUrl() {
        return uploadUrl;
    }

    public void setUploadUrl(String uploadUrl) {
        this.uploadUrl = uploadUrl;
    }

    public String getDocumentUuid() {
        return documentUuid;
    }

    public void setDocumentUuid(String documentUuid) {
        this.documentUuid = documentUuid;
    }
}
